package com.yanqu.road.server.cmd.activity.seacraftsouthsea;

import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SeacraftSouthSeaProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.seacraftsouthsea.SeacraftSouthSeaMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/20 17:21
 */
@Cmd(code = CrossProtocol.C2_SEACRAFT_SOUTH_SEA_ACTION, desc = "南海丝路 进攻 / 突袭 / 使用道具进攻 / 修复")
public class CrossSeacraftSouthSeaActionCmd extends CrossUnionCommand {

    long userId;
    int activityId;
    int type;
    /**
     * 要攻击的联盟id
     */
    String targetUnionId;
    String ownUnionId;
    int dispatchType;
    int titleId;
    int count;
    long preReduceCount;
    int propId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SeacraftSouthSeaProto.SeacraftSouthSeaActionGameToCrossMsg reqMsg = SeacraftSouthSeaProto.SeacraftSouthSeaActionGameToCrossMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        activityId = reqMsg.getCtsMsg().getActivityId();
        targetUnionId = reqMsg.getCtsMsg().getUnionId();
        type = reqMsg.getCtsMsg().getType();
        dispatchType = reqMsg.getCtsMsg().getDispatchType();
        titleId = reqMsg.getTitleId();
        count = reqMsg.getCtsMsg().getCount();
        ownUnionId = reqMsg.getUnionId();
        preReduceCount = reqMsg.getPreReduceCount();
        propId = reqMsg.getPropId();
        if(reqMsg.hasPlayerInfo()){
            CrossUserMgr.updateUserBaseInfo(userId, PlayerBasePb.parseToUserBaseInfo(reqMsg.getPlayerInfo()));
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(GameProtocol.S_SEACRAFT_SOUTH_SEA_ACTION_FROM_CROSS, SeacraftSouthSeaMgr.action(activityId,type,userId,serverId,ownUnionId,targetUnionId,dispatchType,titleId, count,preReduceCount,propId));
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
